// src/api/branch.js
// 党支部信息管理系统 - 所有接口封装（全部 POST）

import { postOk } from './http.js';
import { USE_MOCK_DATA } from './config.js';
import { mockAPI } from './mock.js';

const API = {
  // 1. 党支部基本操作
  list: '/branch/list',
  detail: '/branch/detail',
  create: '/branch/create',
  delete: '/branch/delete',
  update: '/branch/update',
  
  // 2. 支委信息管理
  committeeCreate: '/branch/committee/create',
  committeeUpdate: '/branch/committee/update',
  committeeDelete: '/branch/committee/delete',
  committeeTransition: '/branch/committee/transition',
  
  // 3. 活动记录管理
  activityCreate: '/branch/activity/create',
  activityUpdate: '/branch/activity/update',
  activityDelete: '/branch/activity/delete',
  
  // 4. 党员组织关系转移
  transferMemberRelations: '/branch/transfer-member-relations',
  
  // 5. 批量转换党支部
  batchTransferBranch: '/branch/batch-transfer',
  
  // 6. 导出数据
  exportData: '/branch/export-data',
};

/* -----------------------------------------
 * 1. 党支部基本操作
 * --------------------------------------- */

/** 1.1 获取党支部列表（分页） */
export function getBranchList(payload) {
  if (USE_MOCK_DATA) {
    return mockAPI.branch.list(payload);
  }
  return postOk(API.list, payload);
}

/** 1.2 获取党支部详情 */
export function getBranchById(branchId) {
  if (USE_MOCK_DATA) {
    return mockAPI.branch.detail({ branchId });
  }
  return postOk(API.detail, { branchId });
}

/** 1.3 新增党支部 */
export function createBranch(payload) {
  if (USE_MOCK_DATA) {
    return mockAPI.branch.create(payload);
  }
  return postOk(API.create, payload);
}

/** 1.4 删除党支部 */
export function deleteBranch(branchId) {
  if (USE_MOCK_DATA) {
    return mockAPI.branch.delete({ branchId });
  }
  return postOk(API.delete, { branchId });
}

/** 1.5 修改党支部基本信息 */
export function updateBranch(branchId, updateData) {
  if (USE_MOCK_DATA) {
    return mockAPI.branch.update({ branchId, updateData });
  }
  return postOk(API.update, { branchId, updateData });
}

/* -----------------------------------------
 * 2. 支委信息管理
 * --------------------------------------- */

/** 2.1 新增支委信息 */
export function createCommittee(branchId, committeeData) {
  return postOk(API.committeeCreate, { branchId, committeeData });
}

/** 2.2 修改支委信息 */
export function updateCommittee(branchId, committeeId, updateData) {
  return postOk(API.committeeUpdate, { branchId, committeeId, updateData });
}

/** 2.3 删除支委信息 */
export function deleteCommittee(branchId, committeeId) {
  return postOk(API.committeeDelete, { branchId, committeeId });
}

/** 2.4 支委换届 */
export function committeeTransition(branchId, transitionData) {
  return postOk(API.committeeTransition, { branchId, transitionData });
}

/* -----------------------------------------
 * 3. 活动记录管理
 * --------------------------------------- */

/** 3.1 新增活动记录 */
export function createActivity(branchId, activityData) {
  return postOk(API.activityCreate, { branchId, activityData });
}

/** 3.2 修改活动记录 */
export function updateActivity(branchId, activityId, updateData) {
  return postOk(API.activityUpdate, { branchId, activityId, updateData });
}

/** 3.3 删除活动记录 */
export function deleteActivity(branchId, activityId) {
  return postOk(API.activityDelete, { branchId, activityId });
}

/* -----------------------------------------
 * 4. 党员组织关系转移
 * --------------------------------------- */

/** 4.1 转移党员组织关系 */
export function transferMemberRelations(transferData) {
  return postOk(API.transferMemberRelations, transferData);
}

/* -----------------------------------------
 * 5. 批量转换党支部
 * --------------------------------------- */

/** 5.1 批量转换党支部 */
export function batchTransferBranch(batchData) {
  return postOk(API.batchTransferBranch, batchData);
}

/* -----------------------------------------
 * 6. 导出数据
 * --------------------------------------- */

/** 6.1 导出党支部数据 */
export function exportBranchData(branchId) {
  if (USE_MOCK_DATA) {
    return mockAPI.branch.exportData({ branchId });
  }
  return postOk(API.exportData, { branchId });
}